package com.ncst.backend.controller;

import com.ncst.backend.common.Result;
import com.ncst.backend.domain.MedicalRecord;
import com.ncst.backend.domain.MedicalTechnology;
import com.ncst.backend.service.RegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 患者管理控制器
 * 处理患者相关的请求
 */
@Api(tags = "患者管理")
@RestController
@RequestMapping("/patients")
public class PatientController {

    @Autowired
    private RegisterService registerService;

//    @PostMapping("/search")
//    public Result<List<MedicalRecord>> getByCaseNumberOrRealName(@RequestBody CaseNumberAndRealName params){
//            List<MedicalRecord> res = registerService.getMedicalRecordByCaseNumberOrRealName(params.caseNumber, params.realName);
//            return Result.success(res);
//    }

    @PostMapping("/search")
    public Result<List<MedicalTechnology>> getByCaseNumberOrRealName(@RequestBody CaseNumberAndRealName params){
        List<MedicalTechnology> res = registerService.getMedicalTechnologyByCaseNumberOrRealName(params.caseNumber, params.realName);
        return Result.success(res);
    }

    /**
     * 获取今日患者统计数据
     * <p>
     * 此接口用于统计当日挂号的患者数据，包括：
     * - 今日挂号总数
     * - 今日已接诊患者数
     * - 今日待接诊患者数
     * - 今日已完成看诊患者数
     * - 今日已退号患者数
     *
     * @return 包含今日患者统计数据的Result对象
     */
    @ApiOperation("获取今日患者统计数据")
    @GetMapping("/stats/today")
    public Result<Map<String, Object>> getTodayStats() {
        // 调用服务层获取今日统计数据
        Map<String, Object> stats = registerService.getTodayStats();
        return Result.success(stats);
    }

    @PostMapping("/charge/settle")
    public Result chargeSettle(@RequestBody ChargeSettleParams params) {
        Integer res = registerService.ChargeSettle(params.getItems(), params.getPatientId(), params.getTotalAmount());
        return res > 0 ? Result.success("结算成功") : Result.error("结算失败");
    }

    @Data
    static class ChargeSettleParams {
        private List<Integer> items;
        private Integer patientId;
        private BigDecimal totalAmount;
    }
    @Data
    static class CaseNumberAndRealName {
        private String caseNumber;
        private String realName;
    }
}
